from scipy.optimize import minimize

def negative_profit(params):
    x, y = params
    return -(-0.01 * x**2 - 0.01 * y**2 - 0.007 * x * y + 144 * x + 174 * y - 400000)

# 初始猜测和约束
initial_guess = [1000, 1000]
bounds = [(0, None), (0, None)]
constraints = [
    {'type': 'ineq', 'fun': lambda p: 339 - 0.01*p[0] - 0.003*p[1]},  # P19 ≥ 0
    {'type': 'ineq', 'fun': lambda p: 399 - 0.01*p[1] - 0.004*p[0]}   # P21 ≥ 0
]

result = minimize(negative_profit, initial_guess, method='SLSQP', bounds=bounds, constraints=constraints)

optimal_x = round(result.x[0])
optimal_y = round(result.x[1])
max_profit = -result.fun

print(f"Optimal production: 19-inch={optimal_x}, 21-inch={optimal_y}")
print(f"Maximum profit: ${max_profit:,.2f}")